package com.algorithm.cjm.test;

import java.util.Stack;

/**
 * Created by jieming.chen on 2020/1/28
 */
public class HanNouTan {

    public static void main(String[] args) {
//        Stack<Integer> a = new Stack<>();
//        Stack<Integer> b = new Stack<>();
//        Stack<Integer> c = new Stack<>();
//
//        a.push(5);
//        a.push(4);
//        a.push(3);
//        a.push(2);
//        a.push(1);
//
//        test(a, b, c, "aTob");
//
//        System.out.println(a.toString());
//        System.out.println(b.toString());
//        System.out.println(c.toString());

        test('A', 'B', 'C', 3);
    }

    private static void test(char a, char b, char c, int n) {
        if (n > 0) {
            test(a, c, b, n -1);
            System.out.println(a + " to " + b);
            test(c, b, a, n-1);
        }
    }

    private static void test(Stack<Integer> a, Stack<Integer> b, Stack<Integer> c, String status) {
        if (status.equals("aTob")) {
            test(a, b, c, "bToc");
            if (a.isEmpty()) {
                return;
            }
            b.push(a.pop());
            test(a, b, c, "cTob");
        } else if (status.equals("bToa")) {
            test(a, b, c, "aToc");
            if (b.isEmpty()) {
                return;
            }
            a.push(b.pop());
            test(a, b, c, "cToa");
        } else if (status.equals("bToc")) {
            test(a, b, c, "cToa");
            if (b.isEmpty()) {
                return;
            }
            c.push(b.pop());
            test(a, b, c, "aToc");
        } else if (status.equals("cTob")) {
            test(a, b, c, "bToa");
            if (c.isEmpty()) {
                return;
            }
            b.push(c.pop());
            test(a, b, c, "aTob");
        } else if (status.equals("cToa")) {
            test(a, b, c, "aTob");
            if (c.isEmpty()) {
                return;
            }
            a.push(c.pop());
            test(a, b, c, "bToa");
        } else if (status.equals("aToc")) {
            test(a, b, c, "cTob");
            if (a.isEmpty()) {
                return;
            }
            c.push(a.pop());
            test(a, b, c, "bToc");
        }
    }
}
